#include<linux/kernel.h>
#include<linux/init.h>
#include<linux/module.h>
#include<linux/kdev_t.h>
#include<linux/fs.h>

dev_t dev = 0;

static int __init my_init(void)
{
  if((alloc_chrdev_region(&dev, 0, 1, "my_dev_2")) <0){
    pr_err("Failed to allocate major number for device 1\n");
    return -1;
  }
  pr_info("Major = %d Minor = %d \n",MAJOR(dev), MINOR(dev));
  pr_info("Kernel Module Inserted!\n");

  return 0;
}
/*
** Module exit function
*/
static void __exit my_exit(void)
{
        unregister_chrdev_region(dev, 1);
        printk(KERN_INFO "Kernel Module Removed Successfully...\n");
}
 
module_init(my_init);
module_exit(my_exit);
 
MODULE_LICENSE("GPL");
MODULE_AUTHOR("feifei <feifei@gmail.com>");
MODULE_DESCRIPTION("A simple linux device driver");